import requests
from requests.adapters import HTTPAdapter
import json
import random
import time
import datetime
import re
from concurrent.futures import ThreadPoolExecutor
session = requests.Session()
session.mount('http://', HTTPAdapter(pool_connections=10, pool_maxsize=20))
task_executor = ThreadPoolExecutor(max_workers=10)
# token = "rsource=1320acdbe79dceaac8a47a5bb72c36af3f9a292693e3bf536e960a7c67631e56a%3A2%3A%7Bi%3A0%3Bs%3A7%3A%22rsource%22%3Bi%3A1%3Bs%3A7%3A%22styd.cn%22%3B%7D; sass_gym_wap=1360e5e19ffa2a1218469ce98b6344a5ea38265c70e4cf5a4efd6764bcdc3ddea%3A2%3A%7Bi%3A0%3Bs%3A12%3A%22sass_gym_wap%22%3Bi%3A1%3Bs%3A41%3A%22f0db3383868cc672106848683aff95ea%2322581412%22%3B%7D; sass_gym_base=c27aea988cf2eedfb5521366e4197150f6949f4eb2e297f2ec8e3012c25899e3a%3A2%3A%7Bi%3A0%3Bs%3A13%3A%22sass_gym_base%22%3Bi%3A1%3Bs%3A41%3A%22f0db3383868cc672106848683aff95ea%2322581412%22%3B%7D; club_gym_fav_shop_id=a06d1b9dd6273d5af60a398838bca5d7547e2b1d58ab633d015c36379201f6d6a%3A2%3A%7Bi%3A0%3Bs%3A20%3A%22club_gym_fav_shop_id%22%3Bi%3A1%3Bi%3A575595242%3B%7D; acw_tc=2f61f26516617627923606464e13f85edadfc7f209b791bd912012c98924da; sass_gym_shop_owner=e73efce6c64f5fc20f90a733756bb88347af24ab3c55b51dcb615298a792bed3a%3A2%3A%7Bi%3A0%3Bs%3A19%3A%22sass_gym_shop_owner%22%3Bi%3A1%3Bs%3A8%3A%22d70c2d49%22%3B%7D; Hm_lvt_f4a079b93f8455a44b27c20205cbb8b3=1661734983,1661762792; Hm_lpvt_f4a079b93f8455a44b27c20205cbb8b3=1661763690"
appid = 'mina'

shopid = '1866429561904219'

token = "4Vu4Cn0cz8qJxEhxy9odZjxIFsjHgrLS"

consume_id = 2031737870357329


def timeshow(text='当前时间'):

    # 获取当前时间
    now = datetime.datetime.now()

    # 输出当前时间
    print(f'{text}:{now}')

    # 获取当前时间的毫秒级时间戳
    timestamp = now.timestamp()

    # 输出毫秒级时间戳
    # print("当前时间的毫秒级时间戳为：", timestamp)
    return timestamp


def history_course():
    # request_url = r'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date=2023%2F03%2F13&page=1&size=10'
    request_url = f'https://stmember.styd.cn/v2/training/history_course?course_status=0&page=1&size=10'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x6309092b) XWEB/8555",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/4/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.get(request_url, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()
    print(
        f'get_time{now1}\n耗时{now2-now1}\nurl{request_url}\n结果{responsedata}\n{json.dumps(responsedata)}')

    list1 = responsedata["data"]["list"]
    if len(list1) > 0:
        return False
    else:
        return True


def get_base_number():
    # request_url = r'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date=2023%2F03%2F13&page=1&size=10'
    request_url = f'https://stmember.styd.cn/v1/member/index?'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c33)XWEB/13487",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/4/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.get(request_url, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()
    print(
        f'get_time{now1}\n耗时{now2-now1}\nurl{request_url}\n结果{responsedata}')

    if responsedata.get('data', {}).get('is_login') == 0:
        return False
    else:
        return True

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)


def client_get_formurlencodeddata_requests_proxy0(year, month, day):
    now1 = timeshow(f'start')

    # 请求的 URL
    # url = "http://127.0.0.1:5000/process_date"
    url = "https://hmii.ecovacs-c.com/process_date"
    # 请求的数据，以 JSON 格式发送
    data = {
        "year": year,
        "month": month,
        "day": day
    }

    try:
        # 发送 POST 请求
        r = session.post(url, json=data)
        # 检查响应状态码
        if r.status_code == 200:
            print("请求成功，响应内容：")
        else:
            print(f"请求失败，状态码：{r.status_code}，错误信息：{r.text}")
    except requests.RequestException as e:
        print(f"请求发生异常：{e}")
        return None
    # 客户端发送请求报文到服务端

    now2 = timeshow(f'end ')
    # responsedata = r.text
    responsedata = r.json()
    # responsedatashow = json.dumps(
    #     responsedata, ensure_ascii=False, indent=None)
    print(
        f'get_time{now1}\n耗时{now2-now1}\nurl{url}\n结果:\n{responsedata}')
    # print(
    #     f'get_time{now1}\n耗时{now2-now1}\nurl{request_url}\n结果:\n{pdata}')
    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_0(year, month, day):
    # request_url = r'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date=2023%2F03%2F13&page=1&size=10'
    request_url = f'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date={year}%2F{month}%2F{day}&page=1&size=10'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": ''}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.get(request_url, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(f'get_time{now1},{now2},url{request_url},结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(product_price):
    # request_url = r'https://stmember.styd.cn/v1/appointment/my_coupon_list?shop_id=1866429561904219&course_id=0&course_type=venues&product_price=256'
    # request_url = f'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date={year}%2F{month}%2F{day}&page=1&size=10'
    request_url = f'https://stmember.styd.cn/v1/appointment/my_coupon_list?shop_id={shopid}&course_id=0&course_type=venues&product_price={product_price}'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.get(request_url, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(f'get_time{now1},{now2},url{request_url},结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_1(year, month, day):
    # request_url = r'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date=2023%2F03%2F13&page=1&size=10'
    request_url = f'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date={year}%2F{month}%2F{day}&page=1&size=10'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.get(request_url, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(f'get_time{now1},{now2},url{request_url},结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_v2_common_success_info(id):
    # request_url = r'https://stmember.styd.cn/v1/venues/venues_site_list?id=1875336501985349&date=2023%2F03%2F13&page=1&size=10'
    request_url = f'https://stmember.styd.cn/v2/common/success_info?id={id}&type=5'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.get(request_url, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(f'get_time{now1},{now2},url{request_url},结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_4(year, month, day, venues_site_time):
    # request_url = r'https://stmember.styd.cn/v2/reserve/submit?'
    request_url = r'https://stmember.styd.cn/v2/reserve/submit?'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    payload = {
        "coach_id": 0,
        "consume_id": consume_id,
        "consume_type": "deposit_card",
        "course_id": 0,
        "current_reservation_num": 1,
        "remark": "",
        "reserve_type": "venues",
        "schedule_id": 0,
        "seat": [],
        "venues_date": f"{year}/{month}/{day}",
        "venues_id": "1875336501985349",
        "venues_site_time": venues_site_time
    }
    requestdata = json.dumps(payload).replace(' ', '')
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "Content-Length": f"{len(requestdata)}",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.post(request_url, data=requestdata, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()
    print(
        f'post_time{now1}\n耗时{now2-now1}\nurl{request_url}\n入参{requestdata}\n结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_v1_venues_price(year, month, day, venues_site_time):
    request_url = r'https://stmember.styd.cn/v1/venues/price?'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
#     {
#     "date": "2025/02/22",
#     "venues_id": 1875336501985349,
#     "venues_site_time": [
#         {
#             "end_time": "18:00",
#             "price": "128",
#             "site_id": 1879775233310799,
#             "start_time": "17:00"
#         },
#         {
#             "end_time": "18:00",
#             "price": "128",
#             "site_id": 1880306869731366,
#             "start_time": "17:00"
#         }
#     ]
# }
    payload = {
        "venues_id": "1875336501985349",
        "date": f"{year}/{month}/{day}",
        "venues_site_time": venues_site_time
    }
    requestdata = json.dumps(payload).replace(' ', '')
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "Content-Length": f"{len(requestdata)}",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.post(request_url, data=requestdata, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(
        f'post_time{now1}\n耗时{now2-now1}\nurl{request_url}\n入参{requestdata}\n结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_v1_order_final_price(year, month, day, venues_site_time):
    request_url = r'https://stmember.styd.cn/v1/order/final_price?'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
#     {
#     "date": "2025/02/22",
#     "venues_id": 1875336501985349,
#     "venues_site_time": [
#         {
#             "end_time": "18:00",
#             "price": "128",
#             "site_id": 1879775233310799,
#             "start_time": "17:00"
#         },
#         {
#             "end_time": "18:00",
#             "price": "128",
#             "site_id": 1880306869731366,
#             "start_time": "17:00"
#         }
#     ]
# }
    payload = {
        "deposit_id": consume_id,
        "product_id": "1875336501985349",
        "product_num": 1,
        "product_type": 13,
        "schedule_id": 0,
        "shop_id": shopid,
        "venues_date": f"{year}/{month}/{day}",
        "venues_site_time": venues_site_time
    }
    requestdata = json.dumps(payload).replace(' ', '')
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "Content-Length": f"{len(requestdata)}",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.post(request_url, data=requestdata, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(
        f'post_time{now1}\n耗时{now2-now1}\nurl{request_url}\n入参{requestdata}\n结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_v2_reserve_get_products(year, month, day, venues_site_time):
    request_url = r'https://stmember.styd.cn/v2/reserve/get_products?'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    payload = {
        "product_id": "1875336501985349",
        "product_type": "venues",
        "venues_date": f"{year}/{month}/{day}",
        "venues_site_time": venues_site_time
    }
    requestdata = json.dumps(payload).replace(' ', '')
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "Content-Length": f"{len(requestdata)}",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.post(request_url, data=requestdata, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(
        f'post_time{now1}\n耗时{now2-now1}\nurl{request_url}\n入参{requestdata}\n结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def client_get_formurlencodeddata_requests_3(year, month, day, venues_site_time):
    request_url = r'https://stmember.styd.cn/v2/reserve/get_payment_list?'
    # 功能说明：发送以form表单数据格式（它要求数据名称（name）和数据值（value）之间以等号相连，与另一组name/value值之间用&相连。例如：parameter1=12345&parameter2=23456。）请求到远程服务器，并获取请求响应报文。该请求消息头要求为：{"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"}。
    # 输入参数说明：接收请求的URL;请求报文数据，格式为name1=value1&name2=value2
    # 输出参数：请求响应报文
    # requestJSONdata=str(requestJSONdata).replace("+", "%2B")
    # requestdata=requestJSONdata.encode("utf-8")
    payload = {
        "product_id": "1875336501985349",
        "product_type": "venues",
        "venues_date": f"{year}/{month}/{day}",
        "venues_site_time": venues_site_time
    }
    requestdata = json.dumps(payload).replace(' ', '')
    head = {"Content-Type": "application/json",
            "Host": "stmember.styd.cn",
            "Connection": "keep-alive",
            "Content-Length": f"{len(requestdata)}",
            "theme-compatible": "1",
            "xweb_xhr": "1",
            "Accept": "*/*",
            "Sec-Fetch-Site": "cross-site",
            "Sec-Fetch-Mode": "cors",
            "Sec-Fetch-Dest": "empty",
            "Accept-Encoding": "gzip, deflate, br",
            "Accept-Language": "zh-CN,zh;q=0.9",
            "mina-version": "independent",
            "client-timezone": "+0800",
            "brand-code": "wBAOG13exkK",
            "user-agent": r"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c1f)XWEB/11581",
            "referer": "https://servicewechat.com/wxca2b18fc08dd20a2/3/page-frame.html",
            "app-id": appid,
            "shop-id": shopid,
            "wx-token": token}

    # print '客户端请求JSON报文数据为（客户端 --> 服务端）:\n',requestdata

    # 客户端发送请求报文到服务端
    now1 = timeshow(f'start {request_url}')
    r = session.post(request_url, data=requestdata, headers=head)
    now2 = timeshow(f'end {request_url}')
    responsedata = r.json()

    print(
        f'post_time{now1}\n耗时{now2-now1}\nurl{request_url}\n入参{requestdata}\n结果{responsedata}')

    # 客户端获取服务端的响应报文数据
    # print '服务端的响应报文为（客户端 <--服务端）: ',responsedata
    # print "get the status: ",r.status_code

    # 返回请求响应报文
    # return json.loads(responsedata)
    return responsedata


def wdaytodate(wday):

    now = time.localtime()
    now_wday = now.tm_wday
    difference_value_week = wday-1-now_wday
    if difference_value_week < 0:
        difference_value_week = difference_value_week + 7
    daystamp = time.time() + difference_value_week*24*60*60
    day = time.localtime(daystamp)
    print(day)
    mon = f'{day.tm_mon}'
    if len(mon) == 1:
        mon = f'0{mon}'
    mday = f'{day.tm_mday}'
    if len(mday) == 1:
        mday = f'0{mday}'
    return (day.tm_year, mon, mday)
    # return f'{day.tm_year}-{mon}-{mday}'


def actionweek0():
    # 第一步 查询场地
    # w4_s2
    data = wdaytodate(4)
    # times1 = ['11:00']
    # times1 = ['14:00', '15:00']
    times1 = ['19:00', '20:00']
    # times1 = ['19:00']
    # site_name = "1  号场地"
    site_name = "2  号场地"
    # site_name = "3  号场地"

    print(data)
    year = data[0]
    month = data[1]
    day = data[2]
    venues_site_time = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1 = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2 = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3 = []
    times2 = []
    flag = 1
    site_name_flag_num = 0
    client_get_formurlencodeddata_requests_num = 0
    client_get_formurlencodeddata_requests_1_num = 0
    while (flag == 1 and site_name_flag_num < 1000):
        now = time.localtime()
        if now.tm_hour >= 20 and now.tm_min >= 50:
            # if now.tm_min >= 50:
            print('8点50 取消查询')
            break
        time.sleep(0.45)
        time.sleep(0.1*random.random())
        client_get_formurlencodeddata_requests_num = client_get_formurlencodeddata_requests_num + 1
        if client_get_formurlencodeddata_requests_num % 3 == 0 and now.tm_min >= 30:
            # r = client_get_formurlencodeddata_requests_1(year, month, day)
            # r = client_get_formurlencodeddata_requests_1(year, month, day)
            r = client_get_formurlencodeddata_requests_proxy0(year, month, day)
            client_get_formurlencodeddata_requests_1_num = 0
        else:
            r = client_get_formurlencodeddata_requests_proxy0(year, month, day)
            client_get_formurlencodeddata_requests_1_num = 1

        for list1 in r['data']['list']:
            for itmes in list1['site_data']:

                if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name):
                    if (itmes['status'] == 2):
                        venues_site_time.append({
                            "end_time": itmes['end_time'],
                            "end_timestamp": itmes['end_timestamp'],
                            "start_timestamp": itmes['start_timestamp'],
                            "price": itmes['price'],
                            "site_id": list1["site_id"],
                            "site_name": list1["site_name"],
                            "start_time": itmes['start_time']
                        }
                        )

                        client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time.append({
                            "end_time": itmes['end_time'],
                            "price": itmes['price'],
                            "site_id": list1["site_id"],
                            "start_time": itmes['start_time']
                        }
                        )
                        if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                        if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                        if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                        times2.append(itmes['start_time'])
                        flag = 0
                        print(f'发现可定场地{times2}')
                    print(itmes['member_name'])
                    if (itmes['status'] == 1) and (itmes['member_name'] == ""):
                        flag = 1
                        print('等待开放')

                    if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                        flag = 2
                        print('已经被人订了')
                        # 第四步 发送订单

                site_name_flag = "1  号场地"
                if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name_flag):
                    if (itmes['status'] == 2):
                        print(
                            f'发现铆钉场地已经可定{itmes}_site_name_flag_num_{site_name_flag_num}')
                        site_name_flag_num = site_name_flag_num + 1

                    if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                        flag = 2
                        print(
                            f'发现铆钉场地{itmes}已经可定已经被人订了_site_name_flag_num_{site_name_flag_num}')
                        site_name_flag_num = site_name_flag_num + 1

                        # 第四步 发送订单
    print(venues_site_time)
    # 第三步 判断卡是否有足够剩额
    rr = get_base_number()
    if not rr:
        print('被退出退出')
        exit(0)
    if True:
        # if get_base_number():
        if venues_site_time:
            # if client_get_formurlencodeddata_requests_1_num:
            r = client_get_formurlencodeddata_requests_1(year, month, day)
            time.sleep(0.35)
            time.sleep(0.15*random.random())
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1)
                time.sleep(0.25)
                time.sleep(0.1*random.random())
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1)
                time.sleep(0.25)
                time.sleep(0.1*random.random())
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2)
                time.sleep(0.25)
                time.sleep(0.1*random.random())
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3)
            time.sleep(0.35)
            time.sleep(0.15*random.random())
            rr = client_get_formurlencodeddata_requests_v2_reserve_get_products(
                year, month, day, venues_site_time)
            now_amount_flag = False
            r3 = client_get_formurlencodeddata_requests_3(
                year, month, day, venues_site_time)

            for usable_one in r3['data']['sold_list']['usable_list']:
                if usable_one['id'] == consume_id:
                    now_amount = float(usable_one['now_amount'])
                    deduct_num_str = float(usable_one['deduct_num_str'])
                    if now_amount >= deduct_num_str:
                        print(f'余额为{now_amount},余额足够')
                        now_amount_flag = True
                    else:
                        print(f'余额为{now_amount},余额不足')
                        now_amount_flag = False
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    128)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    256)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    384)
            client_get_formurlencodeddata_requests_v1_order_final_price(
                year, month, day, venues_site_time)
            client_get_formurlencodeddata_requests_v1_order_final_price(
                year, month, day, venues_site_time)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    128)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    256)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    384)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    128)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    256)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    384)
            if not now_amount_flag:
                venues_site_time = []
        print(venues_site_time)

        # 第四步 发送订单

        if venues_site_time:
            while True:
                now = time.localtime()
                if now.tm_sec > 8:
                    time.sleep(0.6861)
                    # if now.tm_min >= 49:
                    break
                if now.tm_sec > 7:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
                if now.tm_sec > 6:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
                if now.tm_sec > 5:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
                if now.tm_sec >= 0:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
            time.sleep(0.15*random.random())
            rr = client_get_formurlencodeddata_requests_4(
                year, month, day, venues_site_time)
            order_id = None
            temp_data = rr.get('data', {}) if hasattr(rr, 'get') else {}
            if isinstance(temp_data, dict):  # 确保操作对象是字典
                order_id = temp_data.get('order_id')
            if order_id:
                client_get_formurlencodeddata_requests_v2_common_success_info(
                    order_id)
                time.sleep(1.8)
                return True
            else:
                return False


def actionweek1(week, time_):
    # 第一步 查询场地
    # w3_s1
    data = wdaytodate(week)
    # times1 = ['11:00']
    # times1 = ['14:00', '15:00']
    times1 = [time_]
    # times1 = ['19:00']
    site_name1 = "3  号场地"
    site_name2 = "2  号场地"
    site_name3 = "1  号场地"

    print(data)
    year = data[0]
    month = data[1]
    day = data[2]
    venues_site_time = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1 = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2 = []
    client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3 = []
    times2 = []
    flag = 1
    site_name_flag_num = 0
    client_get_formurlencodeddata_requests_num = 0
    client_get_formurlencodeddata_requests_1_num = 0
    while (flag == 1 and site_name_flag_num < 1000):
        now = time.localtime()
        if now.tm_hour >= 20 and now.tm_min >= 50:
            # if now.tm_min >= 50:
            print('8点50 取消查询')
            break
        time.sleep(0.45)
        time.sleep(0.1*random.random())
        client_get_formurlencodeddata_requests_num = client_get_formurlencodeddata_requests_num + 1
        if client_get_formurlencodeddata_requests_num % 3 == 0 and now.tm_min >= 30:
            # r = client_get_formurlencodeddata_requests_1(year, month, day)
            r = client_get_formurlencodeddata_requests_1(year, month, day)
            client_get_formurlencodeddata_requests_1_num = 0
        else:
            r = client_get_formurlencodeddata_requests_proxy0(year, month, day)
            client_get_formurlencodeddata_requests_1_num = 1

        for list1 in r['data']['list']:
            for itmes in list1['site_data']:

                if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name1):
                    if (itmes['status'] == 2):
                        venues_site_time.append({
                            "end_time": itmes['end_time'],
                            "end_timestamp": itmes['end_timestamp'],
                            "start_timestamp": itmes['start_timestamp'],
                            "price": itmes['price'],
                            "site_id": list1["site_id"],
                            "site_name": list1["site_name"],
                            "start_time": itmes['start_time']
                        }
                        )

                        client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time.append({
                            "end_time": itmes['end_time'],
                            "price": itmes['price'],
                            "site_id": list1["site_id"],
                            "start_time": itmes['start_time']
                        }
                        )
                        if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                        if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                        if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                        times2.append(itmes['start_time'])
                        flag = 0
                        print(f'发现可定场地{times2}')
                    print(itmes['member_name'])
                    if (itmes['status'] == 1) and (itmes['member_name'] == ""):
                        flag = 1
                        print('等待开放')

                    if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                        flag = 2
                        print('已经被人订了')
                        # 第四步 发送订单

                site_name_flag = "1  号场地"
                if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name_flag):
                    if (itmes['status'] == 2):
                        print(
                            f'发现铆钉场地已经可定{itmes}_site_name_flag_num_{site_name_flag_num}')
                        site_name_flag_num = site_name_flag_num + 1

                    if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                        flag = 2
                        print(
                            f'发现铆钉场地{itmes}已经可定已经被人订了_site_name_flag_num_{site_name_flag_num}')
                        site_name_flag_num = site_name_flag_num + 1

        if not venues_site_time:
            for list1 in r['data']['list']:
                for itmes in list1['site_data']:

                    if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name2):
                        if (itmes['status'] == 2):
                            venues_site_time.append({
                                "end_time": itmes['end_time'],
                                "end_timestamp": itmes['end_timestamp'],
                                "start_timestamp": itmes['start_timestamp'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "site_name": list1["site_name"],
                                "start_time": itmes['start_time']
                            }
                            )

                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                            times2.append(itmes['start_time'])
                            flag = 0
                            print(f'发现可定场地{times2}')
                        print(itmes['member_name'])
                        if (itmes['status'] == 1) and (itmes['member_name'] == ""):
                            flag = 1
                            print('等待开放')

                        if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                            flag = 2
                            print('已经被人订了')
                            # 第四步 发送订单

                    site_name_flag = "1  号场地"
                    if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name_flag):
                        if (itmes['status'] == 2):
                            print(
                                f'发现铆钉场地已经可定{itmes}_site_name_flag_num_{site_name_flag_num}')
                            site_name_flag_num = site_name_flag_num + 1

                        if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                            flag = 2
                            print(
                                f'发现铆钉场地{itmes}已经可定已经被人订了_site_name_flag_num_{site_name_flag_num}')
                            site_name_flag_num = site_name_flag_num + 1

        if not venues_site_time:
            for list1 in r['data']['list']:
                for itmes in list1['site_data']:

                    if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name3):
                        if (itmes['status'] == 2):
                            venues_site_time.append({
                                "end_time": itmes['end_time'],
                                "end_timestamp": itmes['end_timestamp'],
                                "start_timestamp": itmes['start_timestamp'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "site_name": list1["site_name"],
                                "start_time": itmes['start_time']
                            }
                            )

                            client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time.append({
                                "end_time": itmes['end_time'],
                                "price": itmes['price'],
                                "site_id": list1["site_id"],
                                "start_time": itmes['start_time']
                            }
                            )
                            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                                client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3.append({
                                    "end_time": itmes['end_time'],
                                    "price": itmes['price'],
                                    "site_id": list1["site_id"],
                                    "start_time": itmes['start_time']
                                }
                                )
                            times2.append(itmes['start_time'])
                            flag = 0
                            print(f'发现可定场地{times2}')
                        print(itmes['member_name'])
                        if (itmes['status'] == 1) and (itmes['member_name'] == ""):
                            flag = 1
                            print('等待开放')

                        if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                            flag = 2
                            print('已经被人订了')
                            # 第四步 发送订单

                    site_name_flag = "1  号场地"
                    if (itmes['start_time'] in times1) and (itmes['start_time'] not in times2) and (list1["site_name"] == site_name_flag):
                        if (itmes['status'] == 2):
                            print(
                                f'发现铆钉场地已经可定{itmes}_site_name_flag_num_{site_name_flag_num}')
                            site_name_flag_num = site_name_flag_num + 1

                        if (itmes['status'] == 1) and (itmes['member_name'] != ""):
                            flag = 2
                            print(
                                f'发现铆钉场地{itmes}已经可定已经被人订了_site_name_flag_num_{site_name_flag_num}')
                            site_name_flag_num = site_name_flag_num + 1

                        # 第四步 发送订单
    print(venues_site_time)
    # 第三步 判断卡是否有足够剩额
    rr = get_base_number()
    if not rr:
        print('退出')
        exit(0)
    if True:
        # if get_base_number():
        if venues_site_time:
            if client_get_formurlencodeddata_requests_1_num:
                r = client_get_formurlencodeddata_requests_1(year, month, day)
            time.sleep(0.35)
            time.sleep(0.15*random.random())
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1)
                time.sleep(0.25)
                time.sleep(0.1*random.random())
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time1)
                time.sleep(0.25)
                time.sleep(0.1*random.random())
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time2)
                time.sleep(0.25)
                time.sleep(0.1*random.random())
                rr = client_get_formurlencodeddata_requests_v1_venues_price(
                    year, month, day, client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time3)
            time.sleep(0.35)
            time.sleep(0.15*random.random())
            rr = client_get_formurlencodeddata_requests_v2_reserve_get_products(
                year, month, day, venues_site_time)
            now_amount_flag = False
            r3 = client_get_formurlencodeddata_requests_3(
                year, month, day, venues_site_time)

            for usable_one in r3['data']['sold_list']['usable_list']:
                if usable_one['id'] == consume_id:
                    now_amount = float(usable_one['now_amount'])
                    deduct_num_str = float(usable_one['deduct_num_str'])
                    if now_amount >= deduct_num_str:
                        print(f'余额为{now_amount},余额足够')
                        now_amount_flag = True
                    else:
                        print(f'余额为{now_amount},余额不足')
                        now_amount_flag = False
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    128)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    256)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    384)
            client_get_formurlencodeddata_requests_v1_order_final_price(
                year, month, day, venues_site_time)
            client_get_formurlencodeddata_requests_v1_order_final_price(
                year, month, day, venues_site_time)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    128)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    256)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    384)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 1:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    128)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 2:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    256)
            if len(client_get_formurlencodeddata_requests_v1_venues_price_venues_site_time) == 3:
                client_get_formurlencodeddata_requests_v1_appointment_my_coupon_list(
                    384)
            if not now_amount_flag:
                venues_site_time = []
        print(venues_site_time)

        # 第四步 发送订单

        if venues_site_time:
            while True:
                now = time.localtime()
                if now.tm_sec > 8:
                    time.sleep(0.6861)
                    # if now.tm_min >= 49:
                    break
                if now.tm_sec > 7:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
                if now.tm_sec > 6:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
                if now.tm_sec > 5:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
                if now.tm_sec >= 0:
                    # if now.tm_min >= 49:
                    time.sleep(0.6861)
                    break
            time.sleep(0.15*random.random())
            rr = client_get_formurlencodeddata_requests_4(
                year, month, day, venues_site_time)
            order_id = None
            temp_data = rr.get('data', {}) if hasattr(rr, 'get') else {}
            if isinstance(temp_data, dict):  # 确保操作对象是字典
                order_id = temp_data.get('order_id')
            if order_id:
                client_get_formurlencodeddata_requests_v2_common_success_info(
                    order_id)
                time.sleep(1.8)
                return True
            else:
                return False


if __name__ == '__main__':
    # 预先步  检查wx_token 是否有效 被删除
    print('1-20231209')
    sn = 0
    rr = get_base_number()
    if not rr:
        print('退出')
        exit(0)

    time.sleep(15)
    while True:
        now = time.localtime()
        if now.tm_wday == 6:
            break
        time.sleep(6*60*60)
        print(f'{now}等待周日')

    while True:
        now = time.localtime()
        if now.tm_hour == 19:
            break
        time.sleep(1*60*60)
        print(f'{now}等待')

    while True:
        now = time.localtime()
        if now.tm_hour == 20:
            break
        time.sleep(0.5*60*60)
        print(f'{now}等待')

    while True:
        now = time.localtime()
        if now.tm_min >= 26:
            break
        time.sleep(3*60)
        print(f'{now}等待')

    while True:
        now = time.localtime()
        if now.tm_hour >= 20 and now.tm_min >= 29:
            break
        time.sleep(55)
        print(f'{now}等待20：28')

    # 第一轮
    number = 0
    r = actionweek0()
    if not r:
        actionweek0()
    r = actionweek1(3, '19:00')
    if r and number < 2:
        number = number + 1
    r = actionweek1(3, '19:00')
    if r and number < 2:
        number = number + 1
    r = actionweek1(3, '20:00')
    if r and number < 2:
        number = number + 1
    r = actionweek1(3, '20:00')
    if r and number < 2:
        number = number + 1
